#include "mscatteringlidardisplayform.h"
#include "ui_mscatteringlidardisplayform.h"

#include <QDateTimeAxis>
#include <QDateTime>
#include <QSplineSeries>
#include <QValueAxis>
#include <QLegendMarker>


MScatteringLidarDisplayForm::MScatteringLidarDisplayForm(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::MScatteringLidarDisplayForm)
{
    ui->setupUi(this);
    InitChart_ExtinctionCoefficient();
}

MScatteringLidarDisplayForm::~MScatteringLidarDisplayForm()
{
    delete ui;
}

void MScatteringLidarDisplayForm::InitChart_ExtinctionCoefficient()
{
    m_chartExtinctionCoefficient = new QChart();

    QSplineSeries* m_series_temperature = new QSplineSeries(m_chartExtinctionCoefficient);
    m_series_temperature->setPen(QPen(QBrush(Qt::blue),2, Qt::PenStyle::SolidLine,
                                      Qt::PenCapStyle::RoundCap, Qt::PenJoinStyle::RoundJoin));


    m_chartExtinctionCoefficient->addSeries(m_series_temperature);


    // 更改标题颜色和字体大小
    QFont titleFont("sans-serif", 12, QFont::Bold);
    m_chartExtinctionCoefficient->setTitleFont(titleFont);
    QBrush titleBrush(Qt::black);
    m_chartExtinctionCoefficient->setTitleBrush(titleBrush);

    // 设置y轴
    QValueAxis *axisY = new QValueAxis();
    axisY->setRange(-100, 100);
    axisY->setTickCount(6);
    axisY->setLabelFormat("%d");


    // 设置x轴
    QDateTimeAxis* axisX = new QDateTimeAxis;
    axisX->setTickCount(4);
    axisX->setFormat("hh:mm");
    axisX->setRange(QDateTime::currentDateTime().addSecs(-60), QDateTime::currentDateTime().addMSecs(500));

    m_chartExtinctionCoefficient->addAxis(axisX, Qt::AlignBottom);
    m_chartExtinctionCoefficient->addAxis(axisY, Qt::AlignmentFlag::AlignLeft);


    m_series_temperature->attachAxis(axisX);
    m_series_temperature->attachAxis(axisY);


    m_chartExtinctionCoefficient->legend()->markers().at(0)->setVisible(true);
    m_chartExtinctionCoefficient->legend()->markers().at(0)->setFont(QFont("微软雅黑",12));
    m_chartExtinctionCoefficient->legend()->markers().at(0)->setPen(QPen(Qt::blue));
    m_series_temperature->setName("消光系数");


    m_chartExtinctionCoefficient->legend()->attachToChart();

    ui->graphicsView->setChart(m_chartExtinctionCoefficient);
    ui->graphicsView->setRenderHint(QPainter::Antialiasing);
}
